      Subroutine Matrix2Dinv(m)
      Real m(2,2)
      Real a, d, r
      
      a = m(1,1)
      d = m(2,2)
      r = a * d - m(1,2) * m(2,1)

      If (abs(r) .lt. 1e-10) Then
!        Write(*,*) "Matrix Singular", 
!     &                       M(1,1), M(1,2), M(2,1), M(2,2)
        m(1,1) = 1.0
        m(1,2) = 0.0
        m(2,1) = 0.0
        m(2,2) = 1.0
      Else  
        m(1,1) = d / r
        m(1,2) = -m(1,2) / r
        m(2,1) = -m(2,1) / r
        m(2,2) = a / r
      Endif

      End Subroutine

C========================================================================
      Subroutine MatrixProd(m, kx, ky)
      Real m(2,2), kx, ky, a, b
      a = kx
      b = ky
      kx = m(1,1) * a + m(1,2) * b
      ky = m(2,1) * a + m(2,2) * b
      End Subroutine
